<template>
  <div class="chart2"></div>
</template>
<script setup>
import { onMounted } from 'vue'
// echats
import * as echarts from 'echarts';

// const data = [
//   { value: 1048, name: '水浒传' },
//   { value: 735, name: '红楼梦' },
//   { value: 580, name: '三国演义' },
//   { value: 484, name: '西游记' },
//   { value: 300, name: '聊斋' }
// ]

const props = defineProps({
  data: Array
})

onMounted(() => {
  // 现在是生命周期的什么阶段？？？
  echarts.init(document.querySelector('.chart2')).setOption({
    title: {
      text: 'Referer of a Website',
      subtext: 'Fake Data',
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      left: 'left'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: '50%',
        data: props.data,
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  });
})
</script>

<style scoped>
.chart2 {
  width: 600px;
  height: 400px;
}
</style>